﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace JCNT.DAL.DB
{
	/// <summary>
	/// 数据访问类:wp_Opt
	/// </summary>
	public partial class wp_Opt
	{
		public wp_Opt()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("ID", "wp_Opt"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from wp_Opt");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(JCNT.Model.DB.wp_Opt model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into wp_Opt(");
			strSql.Append("ID,F_Log,F_M_M,Pas1,Pas2,Pas3)");
			strSql.Append(" values (");
			strSql.Append("@ID,@F_Log,@F_M_M,@Pas1,@Pas2,@Pas3)");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4),
					new SqlParameter("@F_Log", SqlDbType.NVarChar,50),
					new SqlParameter("@F_M_M", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas1", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas2", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas3", SqlDbType.NVarChar,50)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.F_Log;
			parameters[2].Value = model.F_M_M;
			parameters[3].Value = model.Pas1;
			parameters[4].Value = model.Pas2;
			parameters[5].Value = model.Pas3;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(JCNT.Model.DB.wp_Opt model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update wp_Opt set ");
			strSql.Append("F_Log=@F_Log,");
			strSql.Append("F_M_M=@F_M_M,");
			strSql.Append("Pas1=@Pas1,");
			strSql.Append("Pas2=@Pas2,");
			strSql.Append("Pas3=@Pas3");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@F_Log", SqlDbType.NVarChar,50),
					new SqlParameter("@F_M_M", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas1", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas2", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas3", SqlDbType.NVarChar,50),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = model.F_Log;
			parameters[1].Value = model.F_M_M;
			parameters[2].Value = model.Pas1;
			parameters[3].Value = model.Pas2;
			parameters[4].Value = model.Pas3;
			parameters[5].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from wp_Opt ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from wp_Opt ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public JCNT.Model.DB.wp_Opt GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,F_Log,F_M_M,Pas1,Pas2,Pas3 from wp_Opt ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			JCNT.Model.DB.wp_Opt model=new JCNT.Model.DB.wp_Opt();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Log"]!=null && ds.Tables[0].Rows[0]["F_Log"].ToString()!="")
				{
					model.F_Log=ds.Tables[0].Rows[0]["F_Log"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_M_M"]!=null && ds.Tables[0].Rows[0]["F_M_M"].ToString()!="")
				{
					model.F_M_M=ds.Tables[0].Rows[0]["F_M_M"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Pas1"]!=null && ds.Tables[0].Rows[0]["Pas1"].ToString()!="")
				{
					model.Pas1=ds.Tables[0].Rows[0]["Pas1"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Pas2"]!=null && ds.Tables[0].Rows[0]["Pas2"].ToString()!="")
				{
					model.Pas2=ds.Tables[0].Rows[0]["Pas2"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Pas3"]!=null && ds.Tables[0].Rows[0]["Pas3"].ToString()!="")
				{
					model.Pas3=ds.Tables[0].Rows[0]["Pas3"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,F_Log,F_M_M,Pas1,Pas2,Pas3 ");
			strSql.Append(" FROM wp_Opt ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,F_Log,F_M_M,Pas1,Pas2,Pas3 ");
			strSql.Append(" FROM wp_Opt ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "wp_Opt";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

